#include"WebPageSearcher.h"
#include"WebPageQuery.h"
#include"myredis++.h"
#include"SplitToolCppJieba.h"
WebPageSearcher::WebPageSearcher(const string& keys):_sought(keys)
{
SplitToolCppJieba jiebas;
vector<string>sortkey=jiebas.cut(this->_sought);
multimap<string,int> sortmap;
for(int i=0;i<sortkey.size();++i)
{
    pair<string,int>temp{sortkey[i],i};
    sortmap.insert(temp);
}
this->_sought.clear();
for(multimap<string,int>::iterator it=sortmap.begin();it!=sortmap.end();++it)
{
    this->_sought+=it->first;
}
}
void WebPageSearcher::doQuery(SplitToolCppJieba& jieba,string& info)
{
Myredis rs(info);
vector<string>values;
WebPageQuery wbq;
if(rs.get_list(this->_sought,values))
{   
    wbq.getresult(values);
}
else
{
    wbq.doQuery(this->_sought,jieba);
}
}